﻿CREATE TABLE [dbo].[UserScores] (
    [Id]           INT      IDENTITY (1, 1) NOT NULL,
    [Index]        INT      NOT NULL,
    [LocalGoals]   INT      NOT NULL,
    [VisitorGoals] INT      NOT NULL,
    [Score]        INT      NOT NULL,
    [SystemUserId] INT      NOT NULL,
    [TemplateId]   INT      NOT NULL,
    [Date]         DATETIME NOT NULL,
    CONSTRAINT [PK_UserScores] PRIMARY KEY CLUSTERED ([Id] ASC),
    CONSTRAINT [FK_SystemUserUserScore] FOREIGN KEY ([SystemUserId]) REFERENCES [dbo].[SystemUsers] ([Id]),
    CONSTRAINT [FK_TemplateUserScore] FOREIGN KEY ([TemplateId]) REFERENCES [dbo].[Templates] ([Id])
);


GO
CREATE NONCLUSTERED INDEX [IX_FK_TemplateUserScore]
    ON [dbo].[UserScores]([TemplateId] ASC);


GO
CREATE NONCLUSTERED INDEX [IX_FK_SystemUserUserScore]
    ON [dbo].[UserScores]([SystemUserId] ASC);

